<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="component/elementUI/index.css">
    <link rel="stylesheet" href="component/pear/css/pear.css" />
    <link rel="stylesheet" href="style/wangeditor.css">
    <link rel="stylesheet" href="style/index.css">
    <title>Document</title>
</head>
<style>
    body {
        font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
        background-color: #ffffff;
        color: #333333;
    }

    .form-container {
        max-width: 800px;
        margin: 0 auto;
        padding: 20px;
    }

    .section-title {
        background-color: #e6f2ff;
        padding: 12px 16px;
        font-weight: 600;
        margin-bottom: 20px;
        border-radius: 4px;
    }

    .form-group {
        margin-bottom: 16px;
    }

    .form-label {
        display: block;
        margin-bottom: 6px;
        font-weight: 500;
    }

    .form-input,
    .form-select {
        width: 100%;
        padding: 8px 12px;
        border: 1px solid #d1d5db;
        border-radius: 4px;
        background-color: #f9fafb;
        transition: border-color 0.2s;
    }

    .form-input:focus,
    .form-select:focus {
        outline: none;
        border-color: #ff7a45;
        box-shadow: 0 0 0 2px rgba(255, 122, 69, 0.1);
    }

    .required-mark {
        color: #ff4d4f;
        margin-left: 2px;
    }

    .primary-button {
        background-color: #ff7a45;
        color: white;
        border: none;
        padding: 10px 20px;
        border-radius: 4px;
        cursor: pointer;
        font-weight: 500;
        transition: background-color 0.2s;
    }

    .primary-button:hover {
        background-color: #ff5a28;
    }

    .secondary-button {
        background-color: white;
        color: #333333;
        border: 1px solid #d1d5db;
        padding: 10px 20px;
        border-radius: 4px;
        cursor: pointer;
        font-weight: 500;
        transition: all 0.2s;
    }

    .secondary-button:hover {
        border-color: #ff7a45;
        color: #ff7a45;
    }

    .link-text {
        color: #ff7a45;
        text-decoration: none;
    }

    .link-text:hover {
        text-decoration: underline;
    }

    .hint-text {
        color: #8c8c8c;
        font-size: 12px;
        margin-top: 4px;
    }

    .avatar-section {
        display: flex;
        align-items: center;
        margin-bottom: 24px;
    }

    .avatar {
        width: 64px;
        height: 64px;
        border-radius: 50%;
        background-color: #f0f0f0;
        display: flex;
        align-items: center;
        justify-content: center;
        margin-right: 16px;
        font-size: 24px;
        color: #8c8c8c;
    }

    .auth-button {
        background-color: #ff4d4f;
        color: white;
        border: none;
        padding: 6px 12px;
        border-radius: 4px;
        cursor: pointer;
        font-size: 14px;
    }

    .verification-code {
        display: flex;
        gap: 10px;
    }

    .verification-code .form-input {
        flex: 1;
    }

    .get-code-button {
        white-space: nowrap;
        min-width: 120px;
    }

    .checkbox-group {
        display: flex;
        align-items: flex-start;
        gap: 8px;
        margin-bottom: 20px;
    }

    .form-checkbox {
        margin-top: 2px;
    }

    .buttons-container {
        display: flex;
        justify-content: space-between;
        margin-top: 30px;
    }

    .form-section {
        margin-bottom: 30px;
        padding: 20px;
        border: 1px solid #e8e8e8;
        border-radius: 8px;
        background-color: #ffffff;
    }

    /* 响应式设计 */
    @media (max-width: 768px) {
        .form-container {
            padding: 15px;
        }

        .buttons-container {
            flex-direction: column;
            gap: 10px;
        }

        .buttons-container button {
            width: 100%;
        }

        .verification-code {
            flex-direction: column;
        }

        .get-code-button {
            width: 100%;
        }
    }
</style>

<body>
    <div id="app" v-cloak class="form-container">
        <div class="form-section">
            <div v-if="isShow=='0'" style="display: grid; place-items: center;">
                <el-form :model="enterprise_info" ref="enterprise_info" :inline-message="true" style="width: 100%">

                    <el-form-item label="企业全称" prop="Enterprise_Name"
                        :rules="[{ required: true, message: '请输入企业全称', trigger: 'blur' }]">
                        <el-input @change="changeEnterprise" v-model.trim="enterprise_info.Enterprise_Name"
                            placeholder="请输入企业全称" />
                </el-form>
                <div class="buttons-container">
                    <button type="button" class="secondary-button">取消</button>
                    <el-button :type="isValidate == '1' ? 'info': 'primary'" :disabled="isValidate=='1'"
                        @click="handleValidate"> {{isValidate=='0' || isValidate=='1'?'校验':'下一步'}}</el-button>
                </div>
            </div>
            <!-- 注册 -->
            <div v-else-if="isShow=='1'">
                <div>
                    <div class="section-title">基本信息</div>

                    <el-form :model="enterprise_info" ref="enterprise_info" :inline-message="true" style="width: 100%">

                        <el-form-item label="企业全称" prop="Enterprise_Name"
                            :rules="[{ required: true, message: '请输入企业全称', trigger: 'blur' }]">
                            <el-input disabled v-model.trim="enterprise_info.Enterprise_Name" placeholder="请输入企业全称" />
                            <!-- <el-select v-model.trim="dataForm.Enterprise_Info_SerialNumber" placeholder="请选择企业全称" 
                                style="width: 100%;" clearable filterable>
                                    <el-option v-for="(item,index) in enterprise_info" :key="index" :label="item.Enterprise_Name" :value="item.Enterprise_Info_SerialNumber" />
                                </el-select> -->
                        </el-form-item>
                        <el-form-item label="企业类型" prop="Enterprise_Type"
                            :rules="[{ required: true, message: '请输入企业类型', trigger: 'blur' }]">
                            <el-input v-model.trim="enterprise_info.Enterprise_Type" placeholder="请输入企业类型" />
                        </el-form-item>
                        <el-form-item label="统一社会信用代码" prop="Enterprise_Info_SerialNumber"
                            :rules="[{ required: true, message: '请输入统一社会信用代码', trigger: 'blur' }]">
                            <el-input v-model.trim="enterprise_info.Enterprise_Info_SerialNumber"
                                placeholder="请输入统一社会信用代码" />
                        </el-form-item>
                        <el-form-item label="通讯地址省市区" prop="ProvinceNumber"
                            :rules="[{ required: true, message: '请选择通讯地址省市区', trigger: 'blur' }]">
                            <el-input v-model.trim="enterprise_info.ProvinceNumber" placeholder="请选择通讯地址省市区" />
                        </el-form-item>
                        <el-form-item label="详细地址" prop="Detailed_Address"
                            :rules="[{ required: true, message: '请输入详细地址', trigger: 'blur' }]">
                            <el-input v-model.trim="enterprise_info.Detailed_Address" placeholder="请输入详细地址" />
                        </el-form-item>
                        <el-form-item label="邮箱" prop="E_mail"
                            :rules="[{ required: true, message: '请输入邮箱', trigger: 'blur' }]">
                            <el-input v-model.trim="enterprise_info.E_mail" placeholder="请输入邮箱" />
                        </el-form-item>
                    </el-form>
                </div>
                <div>
                    <div class=".form-title">
                        <div class="section-title">开票信息</div>
                    </div>
                    <el-form :model="enterprise_account" ref="enterprise_account" :inline-message="true"
                        style="width: 100%">
                        <el-form-item label="开票名称" prop="Account_Name"
                            :rules="[{ required: true, message: '请输入开票名称', trigger: 'blur' }]">
                            <el-input v-model.trim="enterprise_account.Account_Name" placeholder="请输入开票名称" />
                        </el-form-item>
                        <el-form-item label="开户行" prop="Bank_Name"
                            :rules="[{ required: true, message: '请输入开户行', trigger: 'blur' }]">
                            <el-input v-model.trim="enterprise_account.Bank_Name" placeholder="请输入开户行" />
                        </el-form-item>
                        <el-form-item label="开票账号" prop="Account_Number"
                            :rules="[{ required: true, message: '请输入银行账号', trigger: 'blur' }]">
                            <el-input v-model.trim="enterprise_account.Account_Number" placeholder="请输入银行账号" />
                        </el-form-item>

                    </el-form>
                </div>
                <div>
                    <div class=".form-title">
                        <div class="section-title">法人信息</div>
                    </div>
                    <el-form :model="enterprise_legal_person" ref="enterprise_legal_person" :inline-message="true"
                        style="width: 100%">
                        <el-form-item label="法人代表人姓名" prop="Legal_Person"
                            :rules="[{ required: true, message: '请输入法定代表人姓名', trigger: 'blur' }]">
                            <el-input v-model.trim="enterprise_legal_person.Legal_Person" placeholder="请输入法定代表人姓名" />
                        </el-form-item>
                        <el-form-item label="证件号码" prop="ParseIDCard_Front"
                            :rules="[{required: true,  message: '请输入证件号码', trigger: 'blur' }]">
                            <el-input v-model.trim="enterprise_legal_person.ParseIDCard_Front " placeholder="请输入证件号码" />
                        </el-form-item>

                    </el-form>
                </div>
                <div>
                    <div class=".form-title">
                        <div class="section-title">管理员信息</div>
                    </div>
                    <el-form :model="base_system_user_info" ref="base_system_user_info" :inline-message="true"
                        style="width: 100%">
                        <el-form-item label="管理员姓名" prop="ID_Name"
                            :rules="[{ required: true, message: '请输入管理员姓名', trigger: 'blur' }]">
                            <el-input v-model.trim="base_system_user_info.ID_Name " placeholder="请输入与当前登录手机号实名一致的姓名" />
                        </el-form-item>
                        <el-form-item label="管理员身份证号码" prop="ID_SerialNumber"
                            :rules="[{ required: true, message: '请输入管理员身份证号码', trigger: 'blur' }]">
                            <el-input v-model.trim="base_system_user_info.ID_SerialNumber"
                                placeholder="请输入与当前登录手机号实名一致的身份证号码" />
                        </el-form-item>
                        <el-form-item label="账号" prop="User_Number"
                            :rules="[{ required: true, message: '请输入账号', trigger: 'blur' }]">
                            <el-input v-model.trim="base_system_user_info.User_Number " placeholder="请输入账号" />
                        </el-form-item>
                        <el-form-item label="密码" prop="Pass_Word"
                            :rules="[{ required: true, message: '请输入密码', trigger: 'blur' }]">
                            <el-input v-model.trim="base_system_user_info.Pass_Word" placeholder="请输入密码" />
                        </el-form-item>

                        <!-- <el-form-item label="管理员手机号" prop="Enterprise_Info_SerialNumber"
                        :rules="[{ required: true, message: '请输入管理员手机号', trigger: 'blur' }]">
                        <el-input v-model.trim="base_system_user_info.Enterprise_Info_SerialNumber" placeholder="请输入管理员手机号" />
                    </el-form-item>
                    <p class="hint-text">当前登录的手机号需与管理员实名信息一致，若手机号非本人实名注册，则不可认证，您可在<a href="#"
                            class="link-text">账号安全</a>中更换手机号</p>
                    <el-form-item label="验证码" prop="Enterprise_Info_SerialNumber" 
                        :rules="[{ required: true, message: '请输入验证码', trigger: 'blur' }]">
                        <el-input v-model.trim="base_system_user_info.Enterprise_Info_SerialNumber" placeholder="请输入验证码" />
                        <el-button type="button" class="primary-button get-code-button">获取验证码</el-button>

                        <el-button type="primary" @click="sendVerificationCode" :disabled="countdown > 0">
                            {{ countdown > 0 ? `${countdown}秒后重新获取` : '获取验证码' }}
                        </el-button>

                    </el-form-item>
                    <p class="hint-text">1天最多获取10次短信验证码，超过请明日再来，今天剩余10次</p> -->
                    </el-form>
                </div>
                <!-- <div class="checkbox-group">
                <input type="checkbox" id="agreement" class="form-checkbox">
                <label for="agreement">
                    提交即代表您同意<a href="#" class="link-text">《用户服务协议》</a>、<a href="#" class="link-text">《实名认证服务协议》</a>、<a
                        href="#" class="link-text">《承诺函》</a>和<a href="#" class="link-text">《隐私政策》</a>
                </label>
            </div> -->

                <div class="buttons-container">
                    <!-- <button type="button" class="secondary-button">上一步</button> -->
                    <button type="button" class="primary-button" @click="submitForm">提交</button>
                </div>
            </div>
            <!-- 加入 -->
            <div v-else-if="isShow=='2'">

                <div>
                    <div class=".form-title">
                        <div class="section-title">用户信息</div>
                    </div>
                    <el-form :model="base_system_user_info" ref="base_system_user_info" :inline-message="true"
                        style="width: 100%">
                        <el-form-item label="账号" prop="User_Number"
                            :rules="[{ required: true, validator:User_Number_Validity, trigger: 'blur' }]">
                            <el-input v-model.trim="base_system_user_info.User_Number" placeholder="请输入账号" />
                        </el-form-item>
                        <el-form-item label="密码" prop="Pass_Word"
                            :rules="[{ required: true, message: '请输入密码', trigger: 'blur' }]">
                            <el-input v-model.trim="base_system_user_info.Pass_Word" placeholder="请输入密码" />
                        </el-form-item>
                        <el-form-item label="身份证号码" prop="ID_SerialNumber"
                            :rules="[{ required: true, message: '请输入身份证号码', trigger: 'blur' }]">
                            <el-input v-model.trim="base_system_user_info.ID_SerialNumber" placeholder="请输入身份证号码" />
                        </el-form-item>
                        <el-form-item label="姓名" prop="ID_Name"
                            :rules="[{ required: true, message: '请输入姓名', trigger: 'blur' }]">
                            <el-input v-model.trim="base_system_user_info.ID_Name " placeholder="请输入姓名" />
                        </el-form-item>
                    </el-form>
                </div>

                <div class="buttons-container">
                    <!-- <button type="button" class="secondary-button">上一步</button> -->
                    <button type="button" class="primary-button" @click="submitForm">提交</button>
                </div>

            </div>
            <!-- 修改 -->
            <div v-else-if="isShow=='3'">
                <div>
                    <div class="section-title">基本信息</div>

                    <el-form :model="enterprise_info" ref="enterprise_info" :inline-message="true" style="width: 100%">

                        <el-form-item label="企业全称" prop="Enterprise_Name"
                            :rules="[{ required: true, message: '请输入企业全称', trigger: 'blur' }]">
                            <el-input v-model.trim="enterprise_info.Enterprise_Name" placeholder="请输入企业全称" />
                        </el-form-item>
                        <el-form-item label="企业类型" prop="Enterprise_Type"
                            :rules="[{ required: true, message: '请输入企业类型', trigger: 'blur' }]">
                            <el-input v-model.trim="enterprise_info.Enterprise_Type" placeholder="请输入企业类型" />
                        </el-form-item>
                        <el-form-item label="统一社会信用代码" prop="Enterprise_Info_SerialNumber"
                            :rules="[{ required: true, message: '请输入统一社会信用代码', trigger: 'blur' }]">
                            <el-input v-model.trim="enterprise_info.Enterprise_Info_SerialNumber"
                                placeholder="请输入统一社会信用代码" />
                        </el-form-item>
                        <el-form-item label="通讯地址省市区" prop="ProvinceNumber"
                            :rules="[{ required: true, message: '请选择通讯地址省市区', trigger: 'blur' }]">
                            <el-input v-model.trim="enterprise_info.ProvinceNumber" placeholder="请选择通讯地址省市区" />
                        </el-form-item>
                        <el-form-item label="详细地址" prop="Detailed_Address"
                            :rules="[{ required: true, message: '请输入详细地址', trigger: 'blur' }]">
                            <el-input v-model.trim="enterprise_info.Detailed_Address" placeholder="请输入详细地址" />
                        </el-form-item>
                        <el-form-item label="邮箱" prop="E_mail"
                            :rules="[{ required: true, message: '请输入邮箱', trigger: 'blur' }]">
                            <el-input v-model.trim="enterprise_info.E_mail" placeholder="请输入邮箱" />
                        </el-form-item>
                    </el-form>
                </div>
                <div>
                    <div class=".form-title">
                        <div class="section-title">开票信息</div>
                    </div>
                    <el-form :model="enterprise_account" ref="enterprise_account" :inline-message="true"
                        style="width: 100%">
                        <el-form-item label="开票名称" prop="Account_Name"
                            :rules="[{ required: true, message: '请输入开票名称', trigger: 'blur' }]">
                            <el-input v-model.trim="enterprise_account.Account_Name" placeholder="请输入开票名称" />
                        </el-form-item>
                        <el-form-item label="开户行" prop="Bank_Name"
                            :rules="[{ required: true, message: '请输入开户行', trigger: 'blur' }]">
                            <el-input v-model.trim="enterprise_account.Bank_Name" placeholder="请输入开户行" />
                        </el-form-item>
                        <el-form-item label="开票账号" prop="Account_Number"
                            :rules="[{ required: true, message: '请输入银行账号', trigger: 'blur' }]">
                            <el-input v-model.trim="enterprise_account.Account_Number" placeholder="请输入银行账号" />
                        </el-form-item>

                    </el-form>
                </div>
                <div>
                    <div class=".form-title">
                        <div class="section-title">法人信息</div>
                    </div>
                    <el-form :model="enterprise_legal_person" ref="enterprise_legal_person" :inline-message="true"
                        style="width: 100%">
                        <el-form-item label="法人代表人姓名" prop="Legal_Person"
                            :rules="[{ required: true, message: '请输入法定代表人姓名', trigger: 'blur' }]">
                            <el-input v-model.trim="enterprise_legal_person.Legal_Person" placeholder="请输入法定代表人姓名" />
                        </el-form-item>
                        <el-form-item label="证件号码" prop="ParseIDCard_Front"
                            :rules="[{required: true,  message: '请输入证件号码', trigger: 'blur' }]">
                            <el-input v-model.trim="enterprise_legal_person.ParseIDCard_Front " placeholder="请输入证件号码" />
                        </el-form-item>

                    </el-form>
                </div>
                <div>
                    <div class=".form-title">
                        <div class="section-title">管理员信息</div>
                    </div>
                    <el-form :model="base_system_user_info" ref="base_system_user_info" :inline-message="true"
                        style="width: 100%">
                        <el-form-item label="管理员姓名" prop="ID_Name"
                            :rules="[{ required: true, message: '请输入管理员姓名', trigger: 'blur' }]">
                            <el-input v-model.trim="base_system_user_info.ID_Name " placeholder="请输入与当前登录手机号实名一致的姓名" />
                        </el-form-item>
                        <el-form-item label="管理员身份证号码" prop="ID_SerialNumber"
                            :rules="[{ required: true, message: '请输入管理员身份证号码', trigger: 'blur' }]">
                            <el-input v-model.trim="base_system_user_info.ID_SerialNumber"
                                placeholder="请输入与当前登录手机号实名一致的身份证号码" />
                        </el-form-item>
                        <el-form-item label="账号" prop="User_Number"
                            :rules="[{ required: true, message: '请输入账号', trigger: 'blur' }]">
                            <el-input v-model.trim="base_system_user_info.User_Number " placeholder="请输入账号" />
                        </el-form-item>
                        <el-form-item label="密码" prop="Pass_Word"
                            :rules="[{ required: true, message: '请输入密码', trigger: 'blur' }]">
                            <el-input v-model.trim="base_system_user_info.Pass_Word" placeholder="请输入密码" />
                        </el-form-item>
                    </el-form>
                </div>
                <div class="buttons-container">
                    <!-- <button type="button" class="secondary-button">上一步</button> -->
                    <button type="button" class="primary-button" @click="submitForm">提交</button>
                </div>

            </div>
        </div>
    </div>
    <script type="text/javascript" src="utils/wangeditor.js"></script>
    <script type="text/javascript" src="utils/jquery.min.js"></script>
    <script type="text/javascript" src="utils/jquery.cookie.js"></script>
    <script type="text/javascript" src="utils/vue.min.js"></script>
    <script type="text/javascript" src="utils/vuex.min.js"></script>
    <script type="text/javascript" src="component/elementUI/index.js"></script>
    <script type="text/javascript" src="utils/components.js"></script>
    <script type="text/javascript" src="utils/compressor.js"></script>
    <script type="text/javascript" src="utils/validity.js"></script>
    <script type="text/javascript" src="utils/utils.js"></script>
    <script type="text/javascript" src="utils/http.js"></script>
    <script>
        new Vue({
            el: '#app',
            data() {
                return {
                    isValidate: '0',// 0:未校验  1:校验失败  2:校验成功 注册企业  3:校验成功 加入企业 4:校验成功 修改企业
                    isShow: '0',// 1:注册企业   2:加入企业  3.修改企业
                    // 企业信息
                    enterprise_info: {
                        Row_Status: '2'
                    },
                    // 银行账户
                    enterprise_account: {},
                    enterprise_legal_person: {
                        ParseIDCard_Front: '',
                        ParseIDCard_Back: ''
                    },
                    // 用户账户关联企业
                    base_system_user_mapping_enterprise: {},
                    // 账户信息
                    base_system_user_info: {},
                    // 

                    agreement: false,
                    countdown: 0,
                }
            },
            mounted() {
                /**
                 * 组件配置文件中自动执行方法
                 * 1.this.getColumn(); //查询表头数据
                 * 2.this.getList(this.form); //查询表格数据
                 * 3.this.getTreeData();//查询树
                 */
                // 初始化时可以从后台获取管理员手机号等信息
                // this.enterprise_info.Invoice_Name = this.enterprise_info.Enterprise_Name;
                // this.enterprise_info.Invoice_Credit_Code = this.enterprise_info.Credit_Code;
            },
            methods: {
                async handleValidate() {// 校验
                    if (this.isValidate == '0') {
                        const data = await generalApi.generalQueryBySQLSerialNumberWithClient({
                            SQLSerialNumber: 's_enterprise_info',
                            ExtensionCondition: utf8ToBase64(`Enterprise_Name='${this.enterprise_info.Enterprise_Name}'`)
                        })
                        if (data.length > 0 && data[0].Row_Status == '0') {//查到企业且以通过
                            this.enterprise_info = data[0];
                            this.isValidate = '3';
                            this.$message.success('校验成功！当前企业已注册，可加入该企业');
                        } else if (data.length > 0 && data[0].Row_Status == '2') {//查到企业且审核中
                            this.isValidate = '1';
                            this.$message({
                                message: '校验失败！当前企业已注册，且正在审核',
                                type: 'warning'
                            });
                        } else if (data.length > 0 && data[0].Row_Status == '3') {//查到企业且未通过
                            this.enterprise_info = data[0];
                            this.isValidate = '4';
                            this.$message.success('校验成功！当前企业需修改信息');
                        } else {// 没查到 可以注册
                            this.isValidate = '2';
                            this.$message.success('校验成功！该企业未注册，可注册');
                        }
                    } else if (this.isValidate == '2') { // 注册企业
                        this.isShow = '1'
                    } else if (this.isValidate == '3') { // 加入企业
                        this.isShow = '2'
                    } else if (this.isValidate == '4') { // 修改企业
                        const [res1, res2, res3, res4] = await Promise.allSettled([
                            generalApi.generalQueryBySQLSerialNumberWithClient({
                                SQLSerialNumber: 's_enterprise_account',
                                ExtensionCondition: utf8ToBase64(`Enterprise_Info_SerialNumber='${this.enterprise_info.Enterprise_Info_SerialNumber}'`),
                            }),
                            generalApi.generalQueryBySQLSerialNumberWithClient({
                                SQLSerialNumber: 's_enterprise_legal_person',
                                ExtensionCondition: utf8ToBase64(`Enterprise_Info_SerialNumber='${this.enterprise_info.Enterprise_Info_SerialNumber}'`),
                            }),
                            generalApi.generalQueryBySQLSerialNumberWithClient({
                                SQLSerialNumber: 's_base_system_user_info',
                                ExtensionCondition: utf8ToBase64(`base_system_user_mapping_enterprise.Enterprise_Info_SerialNumber='${this.enterprise_info.Enterprise_Info_SerialNumber}'`),
                            }),
                            generalApi.generalQueryBySQLSerialNumberWithClient({
                                SQLSerialNumber: 's_base_system_user_mapping_enterprise',
                                ExtensionCondition: utf8ToBase64(`Enterprise_Info_SerialNumber='${this.enterprise_info.Enterprise_Info_SerialNumber}'`),
                            })
                        ]);
                        if (res1.status == 'fulfilled' && res1.value.length > 0) {
                            this.enterprise_account = res1.value[0];
                        }
                        if (res2.status == 'fulfilled' && res2.value.length > 0) {
                            this.enterprise_legal_person = res2.value[0];
                        }
                        if (res3.status == 'fulfilled' && res3.value.length > 0) {
                            this.base_system_user_info = res3.value[0];
                        }
                        if (res4.status == 'fulfilled' && res4.value.length > 0) {
                            this.base_system_user_mapping_enterprise = res4.value[0];
                        }

                        this.isShow = '3'
                    }
                },
                async changeEnterprise(val) {
                    this.isValidate = '0'
                },
                async User_Number_Validity(rule, value, callback) {//校验身份证号
                    if (!value) {
                        callback(new Error('请输入手机号'));
                    } else if (!validatemobile(value)) {
                        callback(new Error('请输入正确格式的手机号'));
                    } else {
                        const data = await generalApi.generalQueryBySQLSerialNumberWithClient({
                            SQLSerialNumber: 's_base_system_user_info',
                            ExtensionCondition: utf8ToBase64(`base_system_user_info.User_Number='${value}'`),
                        })
                        const [res1, res2] = await Promise.allSettled([
                            generalApi.generalQueryBySQLSerialNumberWithClient({// 判断账号是否存在
                                SQLSerialNumber: 's_base_system_user_info',
                                ExtensionCondition: utf8ToBase64(`base_system_user_info.User_Number='${this.base_system_user_info.User_Number}'`),
                            }),
                            generalApi.generalQueryBySQLSerialNumberWithClient({// 判断该账号是否已经关联该企业
                                SQLSerialNumber: 's_base_system_user_info',
                                ExtensionCondition: utf8ToBase64(`base_system_user_info.User_Number='${this.base_system_user_info.User_Number}' AND base_system_user_mapping_enterprise.Row_Status = '0' AND base_system_user_mapping_enterprise.Enterprise_Info_SerialNumber='${this.enterprise_info.Enterprise_Info_SerialNumber}'`),
                            }),
                        ])
                        if (res1.value.length > 0 && res2.value.length > 0) {//该账号已加入该企业
                            this.base_system_user_info = data[0];
                            callback(new Error('该账号已加入该企业'));
                        } else if (data.length > 0 && res2.value.length == 0) {//该账号已存在
                            this.base_system_user_info = data[0];
                            callback();
                        } else {//该账号不存在
                            callback();
                        }
                    }
                },

                // 将userInfo对象属性赋值到base_system_user_info中
                mergeUserInfoToBaseSystemUserInfo(userInfo) {
                    if (userInfo && Array.isArray(userInfo) && userInfo.length > 0) {
                        const userData = userInfo[0];
                        if (userData && typeof userData === 'object') {
                            // 让this.base_system_user_info的值覆盖userInfo的值
                            Object.keys(this.base_system_user_info).forEach(key => {
                                if (this.base_system_user_info[key] !== null && this.base_system_user_info[key] !== undefined) {
                                    userData[key] = this.base_system_user_info[key];
                                }
                            });
                            // 然后将合并后的结果赋值回this.base_system_user_info
                            Object.assign(this.base_system_user_info, userData);
                        }
                    } else if (userInfo && typeof userInfo === 'object' && !Array.isArray(userInfo)) {
                        // 让this.base_system_user_info的值覆盖userInfo的值
                        Object.keys(this.base_system_user_info).forEach(key => {
                            if (this.base_system_user_info[key] !== null && this.base_system_user_info[key] !== undefined) {
                                userInfo[key] = this.base_system_user_info[key];
                            }
                        });
                        // 然后将合并后的结果赋值回this.base_system_user_info
                        Object.assign(this.base_system_user_info, userInfo);
                    }
                },

                // 将enterpriseInfo对象属性赋值到enterprise_info中
                mergeEnterpriseInfoToEnterpriseInfo(enterpriseInfo) {
                    if (enterpriseInfo && Array.isArray(enterpriseInfo) && enterpriseInfo.length > 0) {
                        const enterpriseData = enterpriseInfo[0];
                        if (enterpriseData && typeof enterpriseData === 'object') {
                            // 让this.enterprise_info的值覆盖enterpriseInfo的值
                            Object.keys(this.enterprise_info).forEach(key => {
                                if (this.enterprise_info[key] !== null && this.enterprise_info[key] !== undefined) {
                                    enterpriseData[key] = this.enterprise_info[key];
                                }
                            });
                            // 然后将合并后的结果赋值回this.enterprise_info
                            Object.assign(this.enterprise_info, enterpriseData);
                        }
                    } else if (enterpriseInfo && typeof enterpriseInfo === 'object' && !Array.isArray(enterpriseInfo)) {
                        // 让this.enterprise_info的值覆盖enterpriseInfo的值
                        Object.keys(this.enterprise_info).forEach(key => {
                            if (this.enterprise_info[key] !== null && this.enterprise_info[key] !== undefined) {
                                enterpriseInfo[key] = this.enterprise_info[key];
                            }
                        });
                        // 然后将合并后的结果赋值回this.enterprise_info
                        Object.assign(this.enterprise_info, enterpriseInfo);
                    }
                },

                // 提交表单
                async submitForm() {
                    const allValid = await this.validateAllForms();
                    if (allValid) {
                        let lJSONObject_DataSet = new Object();
                        if (this.isShow == '1') { // 注册
                            this.enterprise_info['Children'] = {
                                enterprise_account: [this.enterprise_account],
                                enterprise_legal_person: [this.enterprise_legal_person],
                            }
                            this.base_system_user_info['Children'] = {
                                base_system_user_mapping_enterprise: [{
                                    Enterprise_Info_SerialNumber: this.enterprise_info.Enterprise_Info_SerialNumber
                                }],
                            }
                            lJSONObject_DataSet = {
                                Add: {
                                    base_system_user_info: [this.base_system_user_info],
                                    enterprise_info: [this.enterprise_info],
                                }
                            }
                        } else if (this.isShow == '2') {
                            // 获取原值并合并到base_system_user_info中
                            const userInfo = await httpRequest({
                                url: "/clientOperation/generalQueryByTableNameWithOriginal",
                                type: 'POST',
                                hostApi: 'https://www.essp.top/apiForSupplyChain',
                                data: {
                                    sqlTableName: 'base_system_user_info',
                                    condition: `base_system_user_info.User_Number='${this.base_system_user_info.User_Number}'`,
                                }
                            })
                            // console.log(userInfo);

                            this.mergeUserInfoToBaseSystemUserInfo(userInfo);

                            // 加入的账号可能已经存在 需要判断一下
                            if (Object.keys(this.base_system_user_info).some(item => item.includes('_Original'))) { //该账号已经存在，账号做修改，关联企业做添加
                                lJSONObject_DataSet = {
                                    Add: {
                                        base_system_user_mapping_enterprise: [{
                                            User_Number: this.base_system_user_info.User_Number,
                                            Enterprise_Info_SerialNumber: this.enterprise_info.Enterprise_Info_SerialNumber
                                        }]
                                    },
                                    Modify: {
                                        base_system_user_info: [this.base_system_user_info],
                                    }
                                }
                            } else { //该账号不存在，账号，关联企业做添加
                                this.base_system_user_info['Children'] = {
                                    base_system_user_mapping_enterprise: [{
                                        Enterprise_Info_SerialNumber: this.enterprise_info.Enterprise_Info_SerialNumber
                                    }],
                                }
                                lJSONObject_DataSet = {
                                    Add: {
                                        base_system_user_info: [this.base_system_user_info],
                                    }
                                }
                            }
                        } else if (this.isShow == '3') { // 修改
                            const userInfo = await httpRequest({
                                url: "/clientOperation/generalQueryByTableNameWithOriginal",
                                type: 'POST',
                                hostApi: 'https://www.essp.top/apiForSupplyChain',
                                data: {
                                    sqlTableName: 'base_system_user_info',
                                    condition: `base_system_user_info.User_Number='${this.base_system_user_info.User_Number}'`,
                                }
                            })

                            const enterpriseInfo = await httpRequest({
                                url: "/clientOperation/generalQueryByTableNameWithOriginal",
                                type: 'POST',
                                hostApi: 'https://www.essp.top/apiForSupplyChain',
                                data: {
                                    sqlTableName: 'enterprise_info',
                                    condition: `Enterprise_Name='${this.enterprise_info.Enterprise_Name}'`,
                                }
                            })

                            this.mergeUserInfoToBaseSystemUserInfo(userInfo);
                            this.mergeEnterpriseInfoToEnterpriseInfo(enterpriseInfo);

                            this.enterprise_info.Row_Status = '2';
                            this.enterprise_info['Children'] = {
                                enterprise_account: [this.enterprise_account],
                                enterprise_legal_person: [this.enterprise_legal_person],
                            }
                            this.base_system_user_info['Children'] = {
                                base_system_user_mapping_enterprise: [{
                                    Enterprise_Info_SerialNumber: this.enterprise_info.Enterprise_Info_SerialNumber
                                }],
                            }
                            lJSONObject_DataSet = {
                                Modify: {
                                    base_system_user_info: [this.base_system_user_info],
                                    enterprise_info: [this.enterprise_info],
                                }
                            }
                        }
                        console.log(lJSONObject_DataSet);
                        // return
                        try {
                            const res = await generalApi.generalSaveByRequestBodyWithClient({
                                Data: lJSONObject_DataSet
                            })
                            if (res.Status == 'success') {
                                this.$message({
                                    message: '注册成功!',
                                    type: 'success'
                                })
                            } else {
                                this.$message({
                                    message: '注册失败，请重试！',
                                    type: 'error'
                                })
                            }
                        } catch (error) {
                            console.error(error);
                            this.$message({
                                message: '系统错误，请联系开发者！',
                                type: 'error'
                            })
                        }

                    }
                },
                async validateAllForms() { //校验方法
                    //获取当前页面上所有的Elform
                    let forms = [];
                    for (let key in this.$refs) {
                        const ref = this.$refs[key];
                        if (ref && ref.$options && ref.$options.name == 'ElForm') {
                            forms.push(ref);
                        }
                    }
                    //判断每个Elform的校验是否通过
                    let isfail = false;
                    for (const form of forms) {
                        try {
                            await form.validate();
                        } catch (error) {
                            isfail = true;
                        }
                    }
                    if (isfail) {
                        return false;
                    }
                    return true;
                },
            },

            // watch: {
            //     // 当企业名称或信用代码变化时，同步更新开票信息中的对应字段
            //     'dataForm.Enterprise_Name'(val) {
            //         if (!this.dataForm.Invoice_Name) {
            //             this.dataForm.Invoice_Name = val;
            //         }
            //     },
            //     'dataForm.Credit_Code'(val) {
            //         if (!this.dataForm.Invoice_Credit_Code) {
            //             this.dataForm.Invoice_Credit_Code = val;
            //         }
            //     }

            // },
        })
    </script>

</body>

</html>